<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户管理</title>
</head>
<body>
		<div class="layui-form" lay-filter="userSearchForm">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">工号/姓名</label>
					<div class="layui-input-inline">
						<input type="text" name="workNo" placeholder="请输入工号或姓名查找"
							autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label" style="width:120px;">所属办事处/部门</label>
					<div class="layui-input-inline">
						<input type="text" name="deptName" placeholder="请输入办事处/部门"
							autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" lay-submit=""
						lay-filter="user-search">
						<i class="layui-icon layui-icon-search"></i>
					</button>
				</div>
			</div>
		</div>
	<table class="layui-hide" id="userTable" lay-filter="userTable"></table>
	<script type="text/javascript">
		var index;
		var form = layui.form;
		var userSearchForm = form.render(null,'userSearchForm');
			window.userTable = layui.table;
			var userTableNs = window.userTable.render({
				elem : '#userTable',
				url : window.basePath + '/sys/findAllEmployees',
				headers: {"token" : window.token},
				method: "post",
				height : 'full-250',
				cols : [ [{
					type:'checkbox'
				}, {
					field : 'EmpCode',
					width : 120,
					title : '工号'
				}, {
					field : 'EmpName',
					width : 120,
					title : '姓名'
				}, {
					field : 'Phone',
					width : 120,
					title : '电话号码'
				}, {
					field : 'OrgName',
					title : '所属办事处/部门',
					minWidth : 350
				}, {
					field : 'workType',
					width : 120,
					title : '用户类型',
					templet : '#workTypeTpl'
				}, {
					fixed : 'right',
					width : 70,
					align : 'center',
					toolbar : '#barDemo'
				} ] ],
				text : {
					none : '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
				},
				page : true
			});

			window.userTable.on('tool(userTable)', function(obj) {
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				var tr = obj.tr; //获得当前行 tr 的DOM对象
				if (layEvent === 'del') {
					layer.confirm('真的删除该用户吗？', function(index) {
						index = layer.load(3);
						//向服务端发送删除指令
						$.ajax({
							url:window.basePath+'/sys/deleteEmployees',
							headers: {"token" : window.token},
							type: "post",
							dataType:'json',
							data:{
								emId :data.eId
							},
							success:function(data){
								layer.close(index);
								if(data.success){
									obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
								}
								layer.msg(data.message);
							},
							error:function(data){
								layer.close(index);
								layer.msg('网络异常！');
							}
						});
					});
				}
			});
			
			userSearchForm.on('submit(user-search)',function(data){
				userTableNs.reload({
					where :{
						empCode:data.field.workNo,
						deptName:data.field.deptName
					},
					page:{
		            	curr:1
		            }
				});
				return false;
			});
	</script>

	<script type="text/html" id="workTypeTpl">
{{#  if(d.emType === 0){ }}
	<span style="color: #329706;">内部员工</span>
{{# }else { }}
	<span style="color: #3383f6;">合作用户</span>
{{# } }}
</script>
	<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</body>
</html>